﻿using System;
using UnityEngine;

namespace Sizebox.CharacterEditor
{
	// Token: 0x02000258 RID: 600
	public class MaterialWrapper
	{
		// Token: 0x06000CFE RID: 3326 RVA: 0x000689F0 File Offset: 0x00066BF0
		public MaterialWrapper(Material material, int count)
		{
			this.DefaultMaterial = new Material(material);
			this.Material = material;
			if (material.HasProperty("_Mode"))
			{
				this.RenderMode = material.GetFloat("_Mode");
			}
			this.Id = count.ToString() + material.name;
			this.DefaultData = this.GenerateMaterialData();
			if (this.Material.HasProperty("_DetailNormalMap"))
			{
				this.OriginalDetailTexture = this.Material.GetTexture("_DetailNormalMap");
			}
		}

		// Token: 0x1700017F RID: 383
		// (get) Token: 0x06000CFF RID: 3327 RVA: 0x00068A8C File Offset: 0x00066C8C
		// (set) Token: 0x06000D00 RID: 3328 RVA: 0x00068A94 File Offset: 0x00066C94
		public string Id { get; private set; }

		// Token: 0x17000180 RID: 384
		// (get) Token: 0x06000D01 RID: 3329 RVA: 0x00068A9D File Offset: 0x00066C9D
		// (set) Token: 0x06000D02 RID: 3330 RVA: 0x00068AA5 File Offset: 0x00066CA5
		public Material Material { get; private set; }

		// Token: 0x17000181 RID: 385
		// (get) Token: 0x06000D03 RID: 3331 RVA: 0x00068AAE File Offset: 0x00066CAE
		// (set) Token: 0x06000D04 RID: 3332 RVA: 0x00068AB6 File Offset: 0x00066CB6
		public Material DefaultMaterial { get; private set; }

		// Token: 0x17000182 RID: 386
		// (get) Token: 0x06000D05 RID: 3333 RVA: 0x00068ABF File Offset: 0x00066CBF
		// (set) Token: 0x06000D06 RID: 3334 RVA: 0x00068AC7 File Offset: 0x00066CC7
		public MaterialData DefaultData { get; private set; }

		// Token: 0x17000183 RID: 387
		// (get) Token: 0x06000D07 RID: 3335 RVA: 0x00068AD0 File Offset: 0x00066CD0
		// (set) Token: 0x06000D08 RID: 3336 RVA: 0x00068AEF File Offset: 0x00066CEF
		public Shader Shader
		{
			get
			{
				if (this.Material)
				{
					return this.Material.shader;
				}
				return null;
			}
			set
			{
				this.Material.shader = value;
				if (this.Material.HasProperty("_Mode"))
				{
					this.SetRenderMode(this.Material.GetFloat("_Mode"));
				}
			}
		}

		// Token: 0x17000184 RID: 388
		// (get) Token: 0x06000D09 RID: 3337 RVA: 0x00068B29 File Offset: 0x00066D29
		// (set) Token: 0x06000D0A RID: 3338 RVA: 0x00068B31 File Offset: 0x00066D31
		public bool RemoveTexture
		{
			get
			{
				return this._RemoveTexture;
			}
			set
			{
				this._RemoveTexture = value;
				if (this._RemoveTexture)
				{
					this.Material.mainTexture = null;
				}
				else
				{
					this.Material.mainTexture = this.DefaultMaterial.mainTexture;
				}
			}
		}

		// Token: 0x17000185 RID: 389
		// (get) Token: 0x06000D0B RID: 3339 RVA: 0x00068B6C File Offset: 0x00066D6C
		// (set) Token: 0x06000D0C RID: 3340 RVA: 0x00068B74 File Offset: 0x00066D74
		public bool UseEmission
		{
			get
			{
				return this._UseEmission;
			}
			set
			{
				this._UseEmission = value;
				if (this._UseEmission)
				{
					this.Material.EnableKeyword("_EMISSION");
				}
				else
				{
					this.Material.DisableKeyword("_EMISSION");
				}
			}
		}

		// Token: 0x17000186 RID: 390
		// (get) Token: 0x06000D0D RID: 3341 RVA: 0x00068BAD File Offset: 0x00066DAD
		// (set) Token: 0x06000D0E RID: 3342 RVA: 0x00068BB5 File Offset: 0x00066DB5
		public float RenderMode
		{
			get
			{
				return this._RenderMode;
			}
			set
			{
				this.SetRenderMode(value);
			}
		}

		// Token: 0x17000187 RID: 391
		// (get) Token: 0x06000D0F RID: 3343 RVA: 0x00068BBF File Offset: 0x00066DBF
		// (set) Token: 0x06000D10 RID: 3344 RVA: 0x00068BC7 File Offset: 0x00066DC7
		public int DetailNormalMap { get; private set; }

		// Token: 0x06000D11 RID: 3345 RVA: 0x00068BD0 File Offset: 0x00066DD0
		public void SetDetailNormalMap(int index)
		{
			if (!this.Material.HasProperty("_DetailNormalMap"))
			{
				return;
			}
			if (index == 0)
			{
				this.ResetDetailNormalMap();
				return;
			}
			Texture value;
			if (index == 1)
			{
				value = null;
			}
			else
			{
				int num = index + -2;
				if (num < 0 || num >= this.DetailTextures.Length)
				{
					return;
				}
				value = this.DetailTextures[num];
			}
			this.Material.EnableKeyword("_NORMALMAP");
			this.Material.EnableKeyword("_DETAIL_MULX2");
			this.Material.SetTexture("_DetailNormalMap", value);
			this.DetailNormalMap = index;
		}

		// Token: 0x06000D12 RID: 3346 RVA: 0x00068C6A File Offset: 0x00066E6A
		public void ResetDetailNormalMap()
		{
			if (!this.Material.HasProperty("_DetailNormalMap"))
			{
				return;
			}
			this.Material.SetTexture("_DetailNormalMap", this.OriginalDetailTexture);
			this.DetailNormalMap = 0;
		}

		// Token: 0x06000D13 RID: 3347 RVA: 0x00068C9F File Offset: 0x00066E9F
		public void RegisterDetailTextures(Texture[] detailTextures)
		{
			this.DetailTextures = detailTextures;
		}

		// Token: 0x06000D14 RID: 3348 RVA: 0x00068CA8 File Offset: 0x00066EA8
		public void ResetMaterial()
		{
			this.Material.shader = this.DefaultMaterial.shader;
			this.Material.CopyPropertiesFromMaterial(this.DefaultMaterial);
			this.UseEmission = this.DefaultData.useEmission;
			this.RemoveTexture = this.DefaultData.removeTexture;
		}

		// Token: 0x06000D15 RID: 3349 RVA: 0x00068D04 File Offset: 0x00066F04
		public MaterialData GenerateMaterialData()
		{
			return new MaterialData(this);
		}

		// Token: 0x06000D16 RID: 3350 RVA: 0x00068D0C File Offset: 0x00066F0C
		private bool SetRenderMode(float value)
		{
			int num = Mathf.RoundToInt(value);
			if (!this.Material.HasProperty("_Mode") || num < 0 || num > 3)
			{
				return false;
			}
			this.Material.DisableKeyword("_ALPHATEST_ON");
			this.Material.DisableKeyword("_ALPHABLEND_ON");
			this.Material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			if (num == 1)
			{
				this.Material.EnableKeyword("_ALPHATEST_ON");
			}
			else if (num == 2)
			{
				this.Material.EnableKeyword("_ALPHABLEND_ON");
			}
			else if (num == 3)
			{
				this.Material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
			}
			this.Material.SetFloat("_Mode", (float)num);
			this._RenderMode = (float)num;
			return true;
		}

		// Token: 0x0400120D RID: 4621
		private const string EMISSION_KEYWORD = "_EMISSION";

		// Token: 0x0400120E RID: 4622
		private const string DETAIL_NORMAL_MAP = "_DetailNormalMap";

		// Token: 0x0400120F RID: 4623
		private const string MODE = "_Mode";

		// Token: 0x04001210 RID: 4624
		private const string CUTOUT_KEYWORD = "_ALPHATEST_ON";

		// Token: 0x04001211 RID: 4625
		private const string FADE_KEYWORD = "_ALPHABLEND_ON";

		// Token: 0x04001212 RID: 4626
		private const string TRANSPARENT_KEYWORD = "_ALPHAPREMULTIPLY_ON";

		// Token: 0x04001213 RID: 4627
		private const string NORMAL_MAP_KEYWORD = "_NORMALMAP";

		// Token: 0x04001214 RID: 4628
		private const string DETAIL_MAP_KEYWORD = "_DETAIL_MULX2";

		// Token: 0x04001219 RID: 4633
		private Texture[] DetailTextures;

		// Token: 0x0400121A RID: 4634
		private readonly Texture OriginalDetailTexture;

		// Token: 0x0400121B RID: 4635
		private const int DETAIL_INDEX_OFFSET = -2;

		// Token: 0x0400121C RID: 4636
		private bool _RemoveTexture;

		// Token: 0x0400121D RID: 4637
		private bool _UseEmission;

		// Token: 0x0400121E RID: 4638
		private float _RenderMode;
	}
}
